package cn.edu.neusoft.wuguangsheng.flowerimpression.activity;

import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import cn.edu.neusoft.wuguangsheng.flowerimpression.R;
import cn.edu.neusoft.wuguangsheng.flowerimpression.bean.UserInfoBean;
import cn.edu.neusoft.wuguangsheng.flowerimpression.listener.TListener;
import cn.edu.neusoft.wuguangsheng.flowerimpression.model.UserInfoModel;
import cn.edu.neusoft.wuguangsheng.flowerimpression.service.Service;

public class OtherUserInfoActivity extends BaseActivity {

    ImageView otheruserinfo_img,otheruserinfo_fh;
    TextView otheruserinfo_username,otheruserinfo_sex,otheruserinfo_qianming,otheruserinfo_phone,otheruserinfo_birthday,otheruserinfo_email;
    String userid;
    String img;

    @Override
    void initView() {
        setLayout_file(R.layout.activity_other_user_info);
        otheruserinfo_img = (ImageView)findViewById(R.id.otheruserinfo_img);
        otheruserinfo_username = (TextView)findViewById(R.id.otheruserinfo_username);
        otheruserinfo_sex = (TextView)findViewById(R.id.otheruserinfo_sex);
        otheruserinfo_qianming = (TextView)findViewById(R.id.otheruserinfo_qianming);
        otheruserinfo_phone = (TextView)findViewById(R.id.otheruserinfo_phone);
        otheruserinfo_birthday = (TextView)findViewById(R.id.otheruserinfo_birthday);
        otheruserinfo_fh = (ImageView)findViewById(R.id.otheruserinfo_fh);
        otheruserinfo_email =(TextView) findViewById(R.id.otheruserinfo_email);
        userid = getIntent().getStringExtra("userid");
    }

    @Override
    void initEvent() {
        otheruserinfo_img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(OtherUserInfoActivity.this,PhotoInfoActivity.class);
                intent.putExtra("imgpath",img);
                startActivity(intent);
            }
        });

        otheruserinfo_fh.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        UserInfoModel userInfoModel = new UserInfoModel();
        userInfoModel.getUserInfo(userid, new TListener<UserInfoBean>() {
            @Override
            public void onResponse(UserInfoBean userInfoBean) {
                otheruserinfo_username.setText(userInfoBean.getUser_nickname());
                otheruserinfo_phone.setText(userInfoBean.getUser_phone());
                otheruserinfo_birthday.setText(userInfoBean.getUser_birthday());
                otheruserinfo_qianming.setText(userInfoBean.getUser_signature());
                otheruserinfo_email.setText(userInfoBean.getUser_email());
                String sex = userInfoBean.getUser_sex();
                if (sex.equals("1")){
                    otheruserinfo_sex.setText("先生");
                }
                else {
                    otheruserinfo_sex.setText("女士");
                }

                if (userInfoBean.getUser_photo().equals("1")||userInfoBean.getUser_photo().equals("1.jpg")){
                    if (userInfoBean.getUser_sex().equals("1")){
                        otheruserinfo_img.setImageResource(R.mipmap.nanshi);
                    }
                    else{
                        otheruserinfo_img.setImageResource(R.mipmap.nvshi);
                    }
                }
                else{
                    img = Service.BASE_URL+"flower_impression/public/uploads/"+userInfoBean.getUser_photo();
                    Picasso.with(OtherUserInfoActivity.this).load(img).into(otheruserinfo_img);
                }


            }

            @Override
            public void onFail(String msg) {

            }
        });

    }

    @Override
    void initDate() {

    }
}
